﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace Presentation {
  /// <summary>
  /// Helper object for Presentation Layer
  /// </summary>
  public static class PresentationHelper {

    /// <summary>
    /// 
    /// </summary>
    public enum BindingNavigatorMoveType {
      Next, Previous, First, Last
    }

    private static ImageList imageStateList;
    /// <summary>
    /// Gets the image state list.
    /// </summary>
    public static ImageList ImageStateList {
      get {
        imageStateList = new ImageList( );
        //imageStateList.ImageStream = ( ( System.Windows.Forms.ImageListStreamer ) ( resources.GetObject( "imageStateList.ImageStream" ) ) );
        imageStateList.TransparentColor = System.Drawing.Color.Transparent;
        imageStateList.ColorDepth = ColorDepth.Depth32Bit;
        imageStateList.Images.Add( "0", Properties.Resources.StatusPresent16 ); //.SetKeyName( 0, "StatusPresent16.png" );
        imageStateList.Images.Add( "1", Properties.Resources.StatusAbsent16 ); //.SetKeyName( 1, "StatusAbsent16.png" );
        imageStateList.Images.Add( "2", Properties.Resources.StatusGone16 ); //.SetKeyName( 2, "StatusGone16.png" );

        return imageStateList;
      }
    }

    /// <summary>
    /// Moves the binding.
    /// </summary>
    /// <param name="bindingSource">The binding source.</param>
    /// <param name="moveType">Type of the move.</param>
    public static void MoveBinding( BindingSource bindingSource, BindingNavigatorMoveType moveType ) {
      switch ( moveType ) {
        case PresentationHelper.BindingNavigatorMoveType.Next:
          bindingSource.MoveNext( );
          break;
        case PresentationHelper.BindingNavigatorMoveType.Previous:
          bindingSource.MovePrevious( );
          break;
        case PresentationHelper.BindingNavigatorMoveType.First:
          bindingSource.MoveFirst( );
          break;
        case PresentationHelper.BindingNavigatorMoveType.Last:
          bindingSource.MoveLast( );
          break;
        default:
          break;
      }
    }

    /// <summary>
    /// Vaildates the email string.
    /// </summary>
    /// <param name="email">The email.</param>
    /// <returns></returns>
    public static bool VaildateEmailString( string email ) {

      string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
         @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
         @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
      Regex re = new Regex( strRegex );
      if ( re.IsMatch( email ) )
        return ( true );
      else
        return ( false );
    }

    /// <summary>
    /// Validates the time string.
    /// </summary>
    /// <param name="time">The time.</param>
    /// <returns></returns>
    public static bool ValidateTimeString( string time ) {
      Regex regex = new Regex( "^([0-1][0-9]|[2][0-3]):([0-5][0-9])$" );
      if ( !regex.IsMatch( time ) ) {
        return false;
      } else {
        return true;
      }
    }

  }
}
